Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local environment variables #252 #366

Merged
merged 13 commits into from
Jun 4, 2019

Conversation

mtnrbq
Copy link
Contributor

@mtnrbq mtnrbq commented May 26, 2019

Provide access to local environment variables #252

  • {{$processEnv [%]envVarName}}: Allows the resolution of local machine environment variables to string values. A typical use case is for secret keys that you don't want to commit to source control.
    For example: define shell environment variable
    in .bashrc or similar on windows

    export DEVSECRET="XlII3JUaEZldVg="
    export PRODSECRET="qMTkleUgjclRoRmV1WA=="
    export USERNAME="testUser"

    and with extension setting environment variables.

    "rest-client.environmentVariables": {
        "$shared": {
            "version": "v1"
        },
        "local": {
            "version": "v2",
            "host": "localhost",
            "secretKey": "DEVSECRET"
        },
        "production": {
            "host": "example.com",
            "secretKey" : "PRODSECRET"
        }
    }

    You can refer directly to the key (e.g. PRODSECRET) in the script, for example if running in the production environment

    ### Lookup PRODSECRET from local machine environment
    GET https://{{host}}/{{version}}/values/item1?user={{$processEnv USERNAME}}
    Authorization: {{$processEnv PRODSECRET}}

    or, it can be rewritten to indirectly refer to the key using an extension environment setting (e.g. %secret) to be environment independent using the optional % modifier.

    ### Use secretKey from extension environment settings to determine
    ### which local machine environment variable to use
    GET https://{{host}}/{{version}}/values/item1?user={{$processEnv USERNAME}}
    Authorization: {{$processEnv %secret}}

    envVarName: Mandatory. Specifies the local machine environment variable

    %: Optional. If specified, treats envVarName as an extension setting environment variable, and uses the value of that for the lookup.

@Huachao
Copy link
Owner

Huachao commented May 27, 2019

@mtnrbq thanks for your nice patch, but please consolidate the variable naming like variable name in code and README, and also fix the tslint errors. Thanks in advance.

@mtnrbq
Copy link
Contributor Author

mtnrbq commented May 27, 2019 via email

@Huachao
Copy link
Owner

Huachao commented May 27, 2019

@mtnrbq I don't care about the naming convention, my concern is the naming consistency in your own code and doc like following:
In the README, the new system variable name is $processEnvName, while in the source code it seems to be $processEnv. And in the README, the environment variable sample you provided is secretKey, while in the usage part seems to be secret. I just want to make the code and doc no ambiguous.

BTW, still thanks for your great patch.

@mtnrbq
Copy link
Contributor Author

mtnrbq commented May 27, 2019 via email

@mtnrbq
Copy link
Contributor Author

mtnrbq commented May 27, 2019

@Huachao - documentation updated, and code linted.

Copy link
Owner

@Huachao Huachao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to touch the package-lock.json?

@mtnrbq
Copy link
Contributor Author

mtnrbq commented May 27, 2019

@Huachao - reverted changes to package-lock and removed spurious space

README.md Outdated
@@ -447,10 +451,54 @@ System variables provide a pre-defined set of variables that can be used in any

`public|cn|de|us|ppe`: Optional. Specify top-level domain (TLD) to get a token for the specified government cloud, `public` for the public cloud, or `ppe` for internal testing. Default: TLD of the REST endpoint; `public` if not valid.

`<domain|tenantId>`: Optional. Domain or tenant id for the directory to sign in to. Default: Pick a directory from a drop-down or press `Esc` to use the home directory (`common` for Microsoft Account).
`<domain|tenantId>` : Optional. Domain or tenant id for the directory to sign in to. Default: Pick a directory from a drop-down or press `Esc` to use the home directory (`common` for Microsoft Account).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space removed

README.md Outdated

`aud:<domain|tenantId>`: Optional. Target Azure AD app id (aka client id) or domain the token should be created for (aka audience or resource). Default: Domain of the REST endpoint.
* `{{$guid}}`: Add a RFC 4122 v4 UUID
* `{{$processEnv [%]envVarName}}`: Allows the resolution of local machine environment variables to string values. A typical use case is for secret keys that you don't want to commit to source control.
For example: define shell environment variable
in `.bashrc` or similar on windows
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary to break into two separate lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed line break

README.md Outdated

`aud:<domain|tenantId>`: Optional. Target Azure AD app id (aka client id) or domain the token should be created for (aka audience or resource). Default: Domain of the REST endpoint.
* `{{$guid}}`: Add a RFC 4122 v4 UUID
* `{{$processEnv [%]envVarName}}`: Allows the resolution of local machine environment variables to string values. A typical use case is for secret keys that you don't want to commit to source control.
For example: define shell environment variable
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made singular

"local": {
"version": "v2",
"host": "localhost",
"secretKey": "DEVSECRET"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secret?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now is secretKey in all references

},
"production": {
"host": "example.com",
"secretKey" : "PRODSECRET"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now is secretKey in all references

```
or, it can be rewritten to indirectly refer to the key using an extension environment setting (e.g. ```%secret```) to be environment independent using the optional ```%``` modifier.
```http
### Use secretKey from extension environment settings to determine
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secret

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now is secretKey in all references

@Huachao
Copy link
Owner

Huachao commented May 28, 2019

@mtnrbq another minor suggestion, add the processEnv system variable into httpElementFactory.ts to enable the autocompletion for it.

@Huachao
Copy link
Owner

Huachao commented May 30, 2019

@mtnrbq I have added some comments and thanks for your contribution

return name;
}
} else {
return name;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

@mtnrbq
Copy link
Contributor Author

mtnrbq commented Jun 1, 2019

@mtnrbq another minor suggestion, add the processEnv system variable into httpElementFactory.ts to enable the autocompletion for it.

Added as #369

Copy link
Owner

@Huachao Huachao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also revert the package-lock.json

@@ -343,17 +343,19 @@ For environment variables, each environment comprises a set of key value pairs d
"local": {
"version": "v2",
"host": "localhost",
"token": "test token"
"token": "test token",
"secret": "devSecret"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so consolidate with other references

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Huachao - sorry I'm not quite following your comment.
Would it be worthwhile to merge this PR as is and raise new issue on document clarifications?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package-lock.json reverted

README.md Outdated
```http
### Use secretKey from extension environment settings to determine
### which local machine environment variable to use
<<<<<<< HEAD
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge conflict?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Owner

@Huachao Huachao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meged, thanks

@Huachao Huachao merged commit dd843b8 into Huachao:master Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants